package cn.xfdzx.android.apps.shop.activity;

import android.content.Context;
import android.content.res.ColorStateList;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.adapter.HomeVPAdapter;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.fragment.car.CarVideoCommunityRetailFragment;
import cn.xfdzx.android.apps.shop.fragment.car.CarVideoMarketPurchaseFragment;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;
import cn.xfdzx.android.apps.shop.view.NoScrollViewPager;

//购物车列表
public class GoodCarActivity extends BaseMvpActivity implements ViewPager.OnClickListener {

    LinearLayout llState;
    TabLayout mTabLayout;
    NoScrollViewPager vpFragmentFour;
    private RelativeLayout.LayoutParams item_bar;
    private List<Fragment> mFragments;
    private String[] title = {"零售", "批发"};
    private HomeVPAdapter homeVPAdapter;
    private Context mContext;
    private ImageView iv_location_back;

    @Override
    public int getLayoutId() {
        return R.layout.activity_good_car;
    }

    @Override
    public void initView() {
        mContext = GoodCarActivity.this;
        llState = findViewById(R.id.ll_state);
        mTabLayout = findViewById(R.id.tl_fragment_four_title);
        vpFragmentFour = findViewById(R.id.vp_fragment_four);
        iv_location_back = findViewById(R.id.iv_location_back);
        initHigh();

        mFragments = new ArrayList<>();
        mFragments.add(CarVideoCommunityRetailFragment.newInstance(getIntent().getIntExtra("type", 0)));//社区零售
        mFragments.add(CarVideoMarketPurchaseFragment.newInstance(getIntent().getIntExtra("type", 0)));//市场采购
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        mTabLayout.setTabRippleColor(ColorStateList.valueOf(getResources().getColor(R.color.picture_color_transparent)));

        for (String tab : title) {
            mTabLayout.addTab(mTabLayout.newTab().setText(tab));
        }
        homeVPAdapter = new HomeVPAdapter(getSupportFragmentManager(), title, mFragments);
        vpFragmentFour.setAdapter(homeVPAdapter);

        mTabLayout.setupWithViewPager(vpFragmentFour);

        if (getIntent().getIntExtra("type", 0) == 0) {
            mTabLayout.setTabTextColors(getResources().getColor(R.color.color_FB9129), getResources().getColor(R.color.color_FB9129));
            mTabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.color_FB9129));
            vpFragmentFour.setCurrentItem(0);
        } else {
            mTabLayout.setTabTextColors(getResources().getColor(R.color.color_02C557), getResources().getColor(R.color.color_02C557));
            mTabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.color_02C557));
            vpFragmentFour.setCurrentItem(1);
        }
        iv_location_back.setOnClickListener(this);

    }

    @Override
    public void onDestroy() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        super.onDestroy();
    }

    @Override
    public void showLoading() {

    }

    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        llState.setLayoutParams(item_bar);
    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_location_back:
                finish();
                break;
        }
    }
}
